<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 父级对象
    var father = {
      name : "xiao",
      age : 170,
      money : 948114,
      techang : function () {
        console.log("sleep");
      }
    }
    // 子级对象--
    var child = {
      name : "shang",
      age : 9,
      // money : 14,
      // techang : function () {
      //   console.log("sleep");
      // }
    }
    // 对象之间的继承for...in
      // for (var key in  father){
        // 子级有的提示不需要继承
      //   if (child[key]) {
      //     continue;
      //   }else{
      //     child[key] = father[key];
      //   }
      // }
    
      // 封装一个对象继承的方法
      function extend(father,child) {
      for (var key in  father){
          // 子级有的提示不需要继承
          if (child[key]) {
            continue;
          }else{
            console.log(key);
            child[key] = father[key];
          }
        }
      }
      // 调用函数
      extend(father,child);
      console.log(child);
  </script>
</body>
</html>